import json
import requests

headers = {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Safari/605.1.15',
}

def getWeibo():

    hotMessage = []

    resp: requests.Response = requests.get("https://weibo.com/ajax/side/hotSearch", headers=headers, timeout=20)
    data = json.loads(resp.text)['data']['realtime']

    for i in data:
        try:
            if not "社会新闻" in str(i["category"]):
                continue
        except KeyError:
            continue
        hotMessage.append({
            "message": i["note"],
            "time": i["onboard_time"]
        })
    return hotMessage


if __name__ == '__main__':
    a = getWeibo()
    for i in a:
        print(i)

